﻿using System;
using System.Data;
using System.Collections.Generic;
using JWFW.SFL;
using JWFW.Encrypt;

namespace BaseServer.BRL
{
	public partial class Tool : JWFW.BOL.BaseConfigEntity
	{
		public Tool()
		{
			m_tableName = "t_tool";
			m_hasCode = true;
			m_hasName = true;
			m_hasComment = true;
			m_tblCacheManager.IsEnable = true;
		}

		protected string m_version = string.Empty;
        protected string m_reflectInfo = string.Empty;
		protected string m_downloadLink = string.Empty;
		protected int m_trialDay = 0;
		protected double m_price = 0.0;
		protected string m_specialInfoName = string.Empty;

		/// <summary>
		/// 版本号
		/// </summary>
		public string Version
		{
			get { return m_version; }
			set { m_version = value; }
		}
		/// <summary>
		/// 反射信息
		/// </summary>
		public string ReflectInfo
		{
			get { return m_reflectInfo; }
			set { m_reflectInfo = value; }
		}
		/// <summary>
		/// 下载链接
		/// </summary>
		public string DownloadLink
		{
			get { return m_downloadLink; }
			set { m_downloadLink = value; }
		}
		/// <summary>
		/// 试用天数
		/// </summary>
		public int TrialDay
		{
			get { return m_trialDay; }
			set { m_trialDay = value; }
		}
		/// <summary>
		/// 价格
		/// </summary>
		public double Price
		{
			get { return m_price; }
			set { m_price = value; }
		}
		/// <summary>
		/// 额外信息的名称
		/// </summary>
		public string SpecialInfoName
		{
			get { return m_specialInfoName; }
			set { m_specialInfoName = value; }
		}
        /// <summary>
        /// 获取解码过的反射信息字典
        /// </summary>
        public Dictionary<string, string> ReflectInfos
        {
            get
            {
                var res = new Dictionary<string, string>();
                string[] tmp = CommonOP.SplitString(m_reflectInfo, ";");
                for (int i = 0; i < tmp.Length; i++)
                {
                    string[] kv = CommonOP.SplitString(tmp[i], "=");
                    if (kv.Length == 2 && !res.ContainsKey(kv[0]))
                    {
                        res.Add(kv[0],Base64.Decrypt(kv[1]));
                    }
                }
                return res;
            }
        }

		protected override void FillContainer()
		{
			base.FillContainer();
			m_container.Add("version", m_version);
            m_container.Add("reflectInfo", m_reflectInfo);
			m_container.Add("downloadLink", m_downloadLink);
			m_container.Add("trialDay", m_trialDay);
			m_container.Add("price", m_price);
			m_container.Add("specialInfoName", m_specialInfoName);
		}

		public override bool GetProperties(System.Data.DataRow record)
		{
			if(!base.GetProperties(record))
			{
				return false;
			}
			m_version = this.GetStringValue(record, "version");
            m_reflectInfo = this.GetStringValue(record, "reflectInfo");
			m_downloadLink = this.GetStringValue(record, "downloadLink");
			m_trialDay = this.GetIntValue(record, "trialDay");
			m_price = this.GetDoubleValue(record, "price");
			m_specialInfoName = this.GetStringValue(record, "specialInfoName");
			return true;
		}
	}
}
